package com.ruoyi.his.service.impl;

import java.util.List;
import java.util.Objects;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.his.domain.vo.HisDockorVo;
import com.ruoyi.system.domain.HisHospitalNation;
import com.ruoyi.system.mapper.HisHospitalNationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.his.mapper.HisDockorMapper;
import com.ruoyi.his.domain.HisDockor;
import com.ruoyi.his.service.IHisDockorService;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author Alan
 * @date 2024-03-09
 */
@Service
public class HisDockorServiceImpl implements IHisDockorService
{
    @Autowired
    private HisDockorMapper hisDockorMapper;

    @Autowired
    private HisHospitalNationMapper hisHospitalNationMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public HisDockor selectHisDockorById(Long id)
    {
        HisDockor hisDockor = hisDockorMapper.selectHisDockorById(id);
        if(StringUtils.isNotBlank(hisDockor.getRegisterNumber())){
            HisHospitalNation hisHospitalNation = hisHospitalNationMapper.selectOne(new LambdaQueryWrapper<HisHospitalNation>()
                    .eq(HisHospitalNation::getRegisterNumber, hisDockor.getRegisterNumber()));
            if(Objects.nonNull(hisHospitalNation)){
                hisDockor.setInstitutionName(hisHospitalNation.getInstitutionName());
            }
        }
        return hisDockor;
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param hisDockor 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    public List<HisDockor> selectHisDockorList(HisDockor hisDockor)
    {
        return hisDockorMapper.selectHisDockorList(hisDockor);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param hisDockor 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertHisDockor(HisDockor hisDockor)
    {
        return hisDockorMapper.insertHisDockor(hisDockor);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param hisDockor 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateHisDockor(HisDockor hisDockor)
    {
        return hisDockorMapper.updateHisDockor(hisDockor);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteHisDockorByIds(Long[] ids)
    {
        return hisDockorMapper.deleteHisDockorByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteHisDockorById(Long id)
    {
        return hisDockorMapper.deleteHisDockorById(id);
    }


    @Override
    public List<HisDockorVo> selectDockorList(HisDockor hisDockor) {
        return hisDockorMapper.selectDockorList(hisDockor);
    }
}
